import Taro from '@tarojs/taro'
import config from '@/config'
import request from '@/services/api'

export function uploadImage (filePath) {
  let token = Taro.getStorageSync('token')
  return new Promise((resolve, reject) => {
    Taro.uploadFile({
      url: config.baseUrl + '/upload',
      name: 'myFiles',
      filePath,
      success: res => {
        resolve(JSON.parse(res.data))
      },
      fail: err => {
        reject(err)
      },
      header: {
        'Content-type': 'multipart/form-data',
        token
      }
    })
  })
}

export async function addStraight (title: string, content: string, imgUrl: string) {
  let ret = await request.post('/straight/addStraight', {
    title, content, imgUrl
  })
  return ret?.data?.id
}


export async function addPicture (title: string, content: string, imgUrl: string) {
  let ret = await request.post('/picture/addPicture', {
    title, content, imgUrl
  })
  return ret?.data?.id
}
